package com.captjack.micro.service.message.listener;

import com.captjack.micro.common.entity.EmailMessageEntity;
import com.captjack.micro.common.entity.MessageQueueConstant;
import com.captjack.micro.service.message.handler.EmailService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Description description.....
 *
 * @author Jack Sparrow
 * @version 1.0.0
 * @date 2018/7/22 11:44
 * package com.captjack.micro.service.message.listener
 */
@RabbitListener(queues = {MessageQueueConstant.EMAIL_MESSAGE_TOPIC})
@Component
public class EmailMessageListener {

    /**
     *
     */
    private final EmailService emailService;

    @RabbitHandler
    public void consumerMessageWithSend(EmailMessageEntity emailMessageEntity) {
        try {
            System.out.println(emailService.sendEmail(emailMessageEntity));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Autowired
    public EmailMessageListener(EmailService emailService) {
        this.emailService = emailService;
    }

}
